﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MINERP.MobileMsgSend.Forms
{
    public partial class FrmSearchSended : Form
    {
        public FrmSearchSended()
        {
            InitializeComponent();
        }
        public delegate void PostStr(string inStr);
        public event PostStr PostSqlStr;
        private void checkEdit1_CheckStateChanged(object sender, EventArgs e)
        {
            if (checkEdit1.Checked)
            {
                dateEditUCreateStart.Enabled = true;
                dateEditUCreateEnd.Enabled = true;
                dateEditUCreateStart.DateTime = DateTime.Now;
                dateEditUCreateEnd.DateTime = DateTime.Now;
            }
            else
            {
                dateEditUCreateStart.Enabled = false;
                dateEditUCreateEnd.Enabled = false;
            }
        }

        private void checkEdit2_CheckStateChanged(object sender, EventArgs e)
        {
            if (checkEdit2.Checked)
            {
                dateEditSendStart.Enabled = true;
                dateEditSendEnd.Enabled = true;
                dateEditSendStart.DateTime = DateTime.Now;
                dateEditSendEnd.DateTime = DateTime.Now;
            }
            else
            {
                dateEditSendStart.Enabled = false;
                dateEditSendEnd.Enabled = false;
            }
        }

        private void simpleButtonOk_Click(object sender, EventArgs e)
        {
            string strSQL = " 1=1 ";
            if (!string.IsNullOrEmpty(textBoxUShouxinren.Text.Trim()))
            {
                strSQL += " and it.SendToShopName like'%" + textBoxUShouxinren.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(textBoxUContent.Text.Trim()))
            {
                strSQL += " and it.SendContent like'%" + textBoxUContent.Text.Trim() + "%' ";

            }
            if (comboBoxEditUType.SelectedIndex == 0)
            {
                strSQL += " and it.Type=0";
            }
            else
            {
                strSQL += " and it.Type=1 and it.BookDateTime > cast('" + dateEditUBookStart.DateTime + "' as System.DateTime)  and it.BookDateTime< cast('" + dateEditUBookEnd.DateTime + "' as System.DateTime) ";
            }
            if (checkEdit1.Checked)
            {
                strSQL += "  and it.CreateTime > cast('" + dateEditUCreateStart.DateTime + "' as System.DateTime) and it.CreateTime< cast('" + dateEditUCreateEnd.DateTime + "' as System.DateTime) ";

            }
            if (checkEdit2.Checked)
            {
                strSQL += "  and it.SendTime > cast('" + dateEditUCreateStart.DateTime + "' as System.DateTime) and it.SendTime< cast('" + dateEditUCreateEnd.DateTime + "' as System.DateTime) ";

            }
            PostSqlStr(strSQL);
            this.Close();
        }

        private void FrmSearchSended_Load(object sender, EventArgs e)
        {
            checkEdit1.Checked = false;
            comboBoxEditUType.SelectedIndex = 0;
        }

        private void simpleButtonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        
    }
}
